package com.weimob.mcloud.wechatwork.customer.externalDependencyProxy.artemisMsg;

import com.alibaba.dubbo.config.annotation.Reference;
import com.weimob.mcloud.wechatwork.core.entity.relation.base.ArtemisMsgInfo;
import com.weimob.mcloud.wechatwork.core.enums.base.ArtemisStsEnum;
import com.weimob.mcloud.wechatwork.core.service.base.ArtemisMsgExportService;
import com.weimob.soa.common.utils.SoaUtil;
import com.weimob.zipkin.ZipkinContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * Artemis消息相关接口代理
 *
 * @Author LeoLee
 * @Date 2022/8/31 14:17
 * @Version 1.0
 */
@Slf4j
@Component
public class ArtemisMsgProxy {

    @Reference
    private ArtemisMsgExportService artemisMsgExportService;

    /**
     * 插入异常artemis消息信息
     * @Author LeoLee
     * @Date 14:34 2022/8/31
     * @param createTime
     * @param topic
     * @param artemisUser
     * @param uk
     * @param body
     */
    public Boolean insertArtemisExceptionMsg(Date createTime, String topic, String artemisUser, String uk, String body, String event, String handleMsg) {
        ArtemisMsgInfo artemisMsgInfo = new ArtemisMsgInfo();
        artemisMsgInfo.setCreateTime(createTime);
        artemisMsgInfo.setUpdateTime(createTime);
        artemisMsgInfo.setHandleSts(ArtemisStsEnum.FAILED.getCode());
        artemisMsgInfo.setHandleMsg(handleMsg);
        //Artemis
        artemisMsgInfo.setHandleNum(3);
        artemisMsgInfo.setTraceId(ZipkinContext.getContext().getGlobalTicket());
        artemisMsgInfo.setTopic(topic);
        artemisMsgInfo.setUser(artemisUser);
        artemisMsgInfo.setUk(uk);
        artemisMsgInfo.setEvent(event);
        artemisMsgInfo.setBody(body);
        Boolean insertResult = SoaUtil.unpack(artemisMsgExportService.insertArtemisExceptionMsg(artemisMsgInfo));
        return insertResult;
    }
}
